home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1998 September / Macworld (1998-09).dmg / Shareware World / Info / For Developers / MacZoop 1.8.3 / More Classes / Window Classes / TextStyleUtils.h < prev    next >
Text File  |  1998-06-12  |  3KB  |  112 lines

  1. /*************************************************************************************************
  2. *
  3. *
  4. *            MacZoop - "the framework for the rest of us"         
  5. *
  6. *
  7. *            TextStyleUtils.h    - utilties for dealing with styled TextEdit
  8. *
  9. *
  10. *            © 1998, Graham Cox
  11. *
  12. *
  13. *
  14. *************************************************************************************************/
  15.  
  16.  
  17. #pragma once
  18.  
  19.  
  20. #ifndef __TEXTSTYLEUTILS__
  21. #define    __TEXTSTYLEUTILS__
  22.  
  23. #include <TextEdit.h>
  24.  
  25. enum
  26. {
  27.     kFaceIsContinuous = 1,
  28.     kFontIsContinuous = 2,
  29.     kSizeIsContinuous = 4
  30. };
  31.  
  32. typedef unsigned short    FontRunInfo;
  33.  
  34. #define        MAX_SIZES    99
  35. #define        MAX_FONTS    96
  36.  
  37. // Quickdraw defines plain as being the abscense of all other styles, but for flag
  38. // manipulation, it's handy to set a bit for this, hence:
  39.  
  40. enum
  41. {
  42.     kPlainStyle = 0x80
  43. };
  44.  
  45. // font run info:
  46.  
  47. typedef struct
  48. {
  49.     FontRunInfo        fr;
  50.     StyleField        runStyles;
  51.     StyleField        contStyles;    
  52.     short            numSizes;
  53.     short            numFonts;
  54.     unsigned short    sizes[MAX_SIZES];
  55.     short            fonts[MAX_FONTS];
  56. }
  57. TEStyleRunInfo;
  58.  
  59. // main analysis function:
  60.  
  61. #if _cplusplus
  62. extern "C" {
  63. #endif
  64.  
  65. void    TEGetStyleRunInfo( TEStyleRunInfo* runInfo, TEHandle te );
  66.  
  67. // utils:
  68.  
  69. Boolean    FontInRun( short aFont, TEStyleRunInfo* runInfo, short* index );
  70. Boolean    SizeInRun( short aSize, TEStyleRunInfo* runInfo, short* index );
  71.  
  72. #if _cplusplus
  73. }
  74. #endif
  75.  
  76. /*
  77.  
  78. Sometime you need to know exactly what a run of styles consists of in TextEdit, for example
  79. when maintaining menus to correctly reflect mixed styles in a run. This function provides one
  80. element of this functionality by filling in a <TEStyleRunInfo> structure from the current
  81. selection in a styled TextEdit record. Unlike TEContinuousStyle(), this can report a complete
  82. list of fonts, styles and sizes in a run, not just whether the run is continuous or not.
  83.  
  84. The TEStyleRunInfo record:
  85.  
  86. <fr> is s set of flags indicating which parts of the run are continuous. If any parts are
  87. continuous, the corresponding fields contain the style, font and size info. For this case,
  88. the zeroth element of the array fields contains the information, and the others are undefined.
  89.  
  90. <runStyles> is a bit field followingthe standard form for styles. If the run is not continuous
  91. with respect to styles, this indicates the mix of styles- normally you would check the equivalent
  92. menu items with a dash rather than a checkmark in this case.
  93.  
  94. <contStyles> is a bitfield indicating if the corresponding style is continuous over the run.
  95. If 1, the style is continuous, else discontinuous.
  96.  
  97. <numSizes> for a continuous run of sizes, this is set to 1. For a non-continuous run, this is
  98. set to the number of array elements actually filled in with size info.
  99.  
  100. <numFonts> as above, but for the font info.
  101.  
  102. <sizes> is an array of the different sizes encountered in the run. They are ordered according
  103. to the order in which they were encountered in the text, not in order of size.
  104.  
  105. <fonts> is an array of font IDs encountered in the run. The order is run order.
  106.  
  107.  
  108.  
  109. */
  110.  
  111.  
  112. #endif